package J_S.cours1.Connexion;

public class Connexion {
	private ConnexionInfo connectesInfo;
	private Ensemble connectesMark;
	private Ensemble connectesAdmi;

	public Connexion() {
		connectesInfo = new ConnexionInfo();
		connectesMark = new EnsembleTableBooleens(73);
		;
		connectesAdmi = new EnsembleTableBooleens(46);
		;
	}

	int nombreDeConnectes() {
		return connectesInfo.nombreDeConnectes() + connectesMark.cardinal()
				+ connectesAdmi.cardinal();
	}

	public void connecter(Login login) {
		String subLogin = login.toString().substring(2, 6);
		if (subLogin.compareTo("info") == 0) {
			connectesInfo.connecter(new LoginInfo(login.toString().substring(2,
					9)));
		} else if (subLogin.compareTo("mark") == 0)
			connectesMark.ajouter(login);

		else
			connectesAdmi.ajouter(login);
	}

	public void deconnecter(Login login) {
		String subLogin = login.toString().substring(2, 6);
		if (subLogin.compareTo("info") == 0) {
			connectesInfo.deconnecter(new LoginInfo(login.toString().substring(
					2, 9)));
		} else if (subLogin.compareTo("mark") == 0)
			connectesMark.enlever(login);

		else
			connectesAdmi.enlever(login);

	}

	public boolean estConnecte(Login login) {
		String subLogin = login.toString().substring(2, 6);
		if (subLogin.compareTo("info") == 0) {
			return connectesInfo.estConnecte(new LoginInfo(login.toString()
					.substring(2, 9)));
		}
		if (subLogin.compareTo("mark") == 0)
			return connectesMark.contient(login);

		return connectesAdmi.contient(login);
	}

}
